package com.olocat.cjx.nsims.controller

import com.alibaba.fastjson.JSON
import com.alibaba.fastjson.JSONArray
import com.olocat.cjx.nsims.pojo.notice.Notice
import com.olocat.cjx.nsims.util.JsonString
import com.olocat.cjx.nsims.util.Response
import com.olocat.cjx.nsims.util.WebSocketServer
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RestController
import javax.annotation.Resource

@RestController
class TestController {

//    @PostMapping("/api/auth/login")
//    fun test(@RequestBody data: String?): Response {
//        if (data == null) {
//            println("data is null")
//        } else {
//            val auth = JSON.parseObject(data, User::class.java)
//            println("username: ${auth.username} , password: ${auth.password}")
//        }
//        val user = User(
//                id = "1001",
//                name = "Test",
//                username = "admin",
//                password = "8914de686ab28dc22f30d3d8e107ff6c",
//                avatar = "https://gw.alipayobjects.com/zos/rmsportal/jZUIxmJycoymBprLOUbT.png",
//                status = 1,
//                telephone = "",
//                lastLoginTime = 1534837621348L,
//                creatorId = "admin",
//                createTime = 1497160610259L,
//                deleted = 0,
//                roleId = "admin",
//                lang = "zh-CN",
//                role = null,
//                token = "4291d7da9005377ec9aec4a71ea837f",
//                lastLoginIp = null,
//                merchantCode = null
//        )
//        val token:Token = Token("4291d7da9005377ec9aec4a71ea837f")
////        return Response.builder(user, 200, CustomHeader("1001"))
//        return Response.builder(token, 200)
//    }

//    @RequestMapping("/api/user/info")
//    fun login(): Response {
//        println("go in /api/user/info")
//        val user: User? = JSON.parseObject(JsonString.USER, User::class.java)
//        return Response.builder(user)
//    }

//    @RequestMapping("/api/auth/logout")
//    fun logout(): Response {
//        println("go in /api/auth/logout")
//        return Response.builder(null, "logout success")
//    }

//    @RequestMapping("/api/account/sms")
//    fun sms(): Response {
//        val c = SmsCaptcha(333512)
//        return Response.builder(c)
//    }

    @GetMapping("/api/user/nav")
    fun nav(): Response {
        val userNavs: JSONArray? = JSON.parseArray(JsonString.NAV)
        println("go in /api/user/nav")
        return Response.builder(userNavs)
    }

//    @GetMapping("/api/notice/get")
//    fun notice(): Response {
//        val noticeList = ArrayList<Notice>(2)
//        noticeList.add(Notice(title = "Title", description = "一分钟前", avatar = "https://gw.alipayobjects.com/zos/rmsportal/kISTdvpyTAhtGxpovNWd.png", href = "#"))
//        return Response.builder(noticeList)
//    }

    @GetMapping("/api/test")
    fun websoket() {
        println("go in /api/test")
        WebSocketServer.sendInfo("1", "i.toString()")
    }
}